// components/tab-bar/tab-bar.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    name: "聊愈",
    indexPath: "index-acitve",
    indexWidth: "100rpx",
    logPath: "log",
    logWidth: "45rpx",
    worldPath: "world",
    worldWidth: "45rpx",
    testPath: "test",
    testWidth: "45rpx",
    myPath: "my",
    myWidth: "45rpx",
  },
  lifetimes: {
    attached: function () {
      const app = getApp();
      if (app.globalData.name != "11") {
        this.name = app.globalData.name
        this.jump()
      }
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    jump() {

      if (this.name == '聊愈') {
        this.setData({
          indexPath: "index-acitve",
          indexWidth: "100rpx",
          name: "聊愈"
        });
      } else {
        this.setData({
          indexPath: "index",
          indexWidth: "45rpx"
        });
      }

      if (this.name == '日志') {
        this.setData({
          logPath: "log-active",
          logWidth: "100rpx",
          name: "日志"
        });
      } else {
        this.setData({
          logPath: "log",
          logWidth: "45rpx"
        });
      }

      if (this.name == '世界') {
        this.setData({
          worldPath: "world-active",
          worldWidth: "100rpx"
        });
      } else {
        this.setData({
          worldPath: "world",
          worldWidth: "45rpx"
        });
      }

      if (this.name == '测试') {
        this.setData({
          testPath: "test-active",
          testWidth: "100rpx"
        });
      } else {
        this.setData({
          testPath: "test",
          testWidth: "45rpx"
        });
      }

      if (this.name == '我的') {
        this.setData({
          myPath: "my-active",
          myWidth: "100rpx"
        });
      } else {
        this.setData({
          myPath: "my",
          myWidth: "45rpx"
        });
      }
    },
    handleTap(e) {
      const app = getApp();
      app.globalData.name = e.currentTarget.dataset.name,
      this.name = app.globalData.name
      if (this.name == '聊愈') {
        wx.redirectTo({
          url: '/pages/home/home'
        })
        this.setData({
          indexPath: "index-acitve",
          indexWidth: "100rpx",
          name: "聊愈"
        });


      } else {
        this.setData({
          indexPath: "index",
          indexWidth: "45rpx"
        });
      }

      if (this.name == '日志') {
        wx.redirectTo({
          url: '/pages/log/log'
        })
        this.setData({
          logPath: "log-active",
          logWidth: "100rpx",
          name: "日志"
        });
      } else {
        this.setData({
          logPath: "log",
          logWidth: "45rpx"
        });
      }

      if (this.name == '世界') {
        wx.redirectTo({
          url: '/pages/world/world'
        })
        this.setData({
          worldPath: "world-active",
          worldWidth: "100rpx"
        });
      } else {
        this.setData({
          worldPath: "world",
          worldWidth: "45rpx"
        });
      }

      if (this.name == '测试') {
        wx.redirectTo({
          url: '/pages/test/test'
        })
        this.setData({
          testPath: "test-active",
          testWidth: "100rpx"
        });
      } else {
        this.setData({
          testPath: "test",
          testWidth: "45rpx"
        });
      }

      if (this.name == '我的') {
        wx.redirectTo({
          url: '/pages/my/my'
        })
        this.setData({
          myPath: "my-active",
          myWidth: "100rpx"
        });
      } else {
        this.setData({
          myPath: "my",
          myWidth: "45rpx"
        });
      }
    }
  }
})